package com.zhilianbao.leyaogo.ui.adapter.me;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bql.recyclerview.swipe.SwipeMenuAdapter;
import com.bql.utils.DateUtils;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.model.response.me.HistoryResponse;

import java.util.List;

/**
 * Created by liu on 2016/10/26.
 * 历史adapter
 */
public class HistoryAdapter extends SwipeMenuAdapter<HistoryAdapter.HistoryViewHolder> {
    private List<HistoryResponse> mList;
    private Context mContext;

    public HistoryAdapter(Context context, List<HistoryResponse> list) {
        mList = list;
        this.mContext = context;
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_history, parent, false);
    }

    @Override
    public HistoryAdapter.HistoryViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new HistoryAdapter.HistoryViewHolder(realContentView);
    }

    @Override
    public void onBindViewHolder(HistoryAdapter.HistoryViewHolder holder, int position) {
        holder.setData(mContext, mList.get(position));

    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }


    static class HistoryViewHolder extends RecyclerView.ViewHolder {

        private TextView mTvRechargeNum;
        private TextView mTvRechargeDate;

        public HistoryViewHolder(View itemView) {
            super(itemView);
            mTvRechargeNum = (TextView) itemView.findViewById(R.id.tv_recharge_num);
            mTvRechargeDate = (TextView) itemView.findViewById(R.id.tv_recharge_date);
        }

        public void setData(Context context, HistoryResponse historyResponse) {
            mTvRechargeNum.setText(historyResponse.getIncomeAmount() + "元");
            String date = DateUtils.format(historyResponse.getCreateTime(), "yyyy-MM-dd");
            mTvRechargeDate.setText(date);
        }
    }
}
